package com.ruoyi.web.message.controller;
import java.util.Arrays;
import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.ruoyi.common.utils.SecurityUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.web.message.domain.Message;
import com.ruoyi.web.message.service.IMessageService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 消息Controller
 *
 * @author 范书铭
 * @date 2024-10-11
 */
@Api("消息")
@RestController
@RequestMapping("/message/message")
public class MessageController extends BaseController {
    @Autowired
    private IMessageService messageService;

/**
 * 查询消息列表
 */
@ApiOperation("查询消息列表")
@PreAuthorize("@ss.hasPermi('message:message:list')")
@GetMapping("/list")
    public TableDataInfo list(Message message) {
        startPage();
        List<Message> list = messageService.selectMessageList(message);
        return getDataTable(list);
    }


    /**
     * 获取消息详细信息
     */
    @ApiOperation("获取消息详细信息")
    @PreAuthorize("@ss.hasPermi('message:message:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(messageService.getMessageById(id, SecurityUtils.getUserId()));
    }

    /**
     * 新增消息
     */
    @ApiOperation("新增消息")
    @PreAuthorize("@ss.hasPermi('message:message:add')")
    @Log(title = "消息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody Message message) {
        return toAjax(messageService.save(message));
    }

    /**
     * 修改消息
     */
    @ApiOperation("修改消息")
    @PreAuthorize("@ss.hasPermi('message:message:edit')")
    @Log(title = "消息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody Message message) {
        return toAjax(messageService.save(message));
    }

    /**
     * 删除消息
     */
    @ApiOperation("删除消息")
    @PreAuthorize("@ss.hasPermi('message:message:remove')")
    @Log(title = "消息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(messageService.removeByIds(Arrays.asList(ids)));
    }
}
